package sync1;

/**
 * @Auther: 杨通通
 * @Date: 2024/11/22 22:24
 * @Description:
 */
public class intervalOut {

    public static void main(String[] args) {
        Run run = new Run();
        new  Thread(run,"线程1").start();
        new  Thread(run,"线程2").start();
    }

}

class Run implements Runnable{
    private  Integer count = 0;

    @Override
    public void run() {

       synchronized (this){
           while (count < 100){
               System.out.println(Thread.currentThread().getName()+":"+(++count));
               notify();
               try {
                   wait();
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }

           }
           notify();
       }
    }
}